import random
# ip的读取与存储 120000个
# 172.25.254.0 - 255

# 初始化
all_list = []
an_list = []
n = 0


def myFunc(e):
    return e['count']


# 写入ip
fp = open('ips.txt', 'a+', buffering=1)
for i in range(120000):
    num = random.randint(0, 255)
    all_list.append(num)
    fp.write(f'172.25.254.{num}\n')
fp.close()

print("正在统计，预计需要一分钟...请稍等...")
# 统计
for i in list(set(all_list)):
    for j in all_list:
        if set(list(str(i))) == set(list(str(j))):
            n = n + 1
    an_list.append({'ip': f'172.25.254.{i}', 'count': n})

    # 重置
    n = 0


# 排序
an_list.sort(key=myFunc, reverse=True)

# 取出前十
for i in range(1, 11):
    print(f"第{i}名：{an_list[i]['ip']}出现了{an_list[i]['count']}次")



